//
//  NetworkService.swift
//  swiftProductTemplate
//
//  Created by 刘圣洁 on 2025/6/20.
//

import Moya
import RxSwift

///内部代码都是示例，开发时删除，按自己的项目写
class NetworkService {
    private let provider = MoyaProvider<MyAPI>()
    
    func fetchUsers() -> Single<[User]> {
        return provider.rx.request(.fetchUsers)
            .map([User].self)
            .catch { error in
                print("Error fetching users: \(error)")
                return .error(error)
            }
    }
    
    func createUser(name: String, age: Int) -> Single<User> {
        return provider.rx.request(.createUser(name, age))
            .map(User.self)
            .catch { error in
                print("Error creating user: \(error)")
                return .error(error)
            }
    }
    
    func fetchUser(id: Int) -> Single<User> {
        return provider.rx.request(.fetchUser(id))
            .map(User.self)
            .catch { error in
                print("Error fetching user: \(error)")
                return .error(error)
            }
    }
}
